package com.hz.controller;

import com.hz.dao.UserWithdrawDepositDao;
import com.hz.pojo.UserWithdrawDeposit;
import com.hz.pojo.WithdrawDeposit;
import com.hz.service.UserWithdrawDepositService;
import com.hz.service.impl.UserWithdrawDepositServiceImpl;
import com.hz.utils.DateUtils;
import com.hz.utils.MassageJsons;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/UserWithdrawDeposit")
public class UserWithdrawDepositController {
    @Resource
    UserWithdrawDepositServiceImpl userWithdrawDepositService;
    @Resource
    UserWithdrawDepositDao userWithdrawDepositDao;

    /**
     * 根据提现状态查询提现记录，分页
     */
    @RequestMapping("/getUserWithdrawDeposit")
    public MassageJsons getUserWithdrawDeposit(Integer pages, Integer pageSize,Integer state,String user_name){
        System.out.println("pages==========="+pages);
        System.out.println("pageSize==========="+pageSize);
        System.out.println("state==========="+state);
        System.out.println("user_name==========="+user_name);
        try {
            if(pages!=null && pageSize!=null){
                /*start:就是当前页的起始索引,pageSize就是每页的条数
                pages:就是当前页
                */
                int start=(pages-1) * pageSize;
                return new MassageJsons("0","请求成功",userWithdrawDepositService.getUserWithdrawDeposit(start,pageSize,state,user_name),
                        userWithdrawDepositDao.getUserWithdrawDepositCount(state,user_name));
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
        return new MassageJsons("1","请求失败");
    }

    /**
     * 更改提现状态
     */
    @RequestMapping("/updUserWithdrawDeposit")
    public MassageJsons updUserWithdrawDeposit(@RequestBody HashMap<String,Object> hashMap){
        int i = 0;
        try {
        WithdrawDeposit withdrawDeposit = new WithdrawDeposit();
        withdrawDeposit.setAdmin_id(Long.parseLong(hashMap.get("admin_id")+""));
        withdrawDeposit.setWithdrawDeposit_getmoney_state(Integer.parseInt(hashMap.get("withdrawDeposit_getmoney_state")+""));
        withdrawDeposit.setWithdrawDeposit_id(Long.parseLong(hashMap.get("withdrawDeposit_id")+""));
        withdrawDeposit.setWithdrawDeposit_review_time(DateUtils.getCurrentTime());
            i = userWithdrawDepositService.updUserWithdrawDeposit(withdrawDeposit);
            if(i!=0){
                Integer pages = Integer.parseInt(hashMap.get("pages")+"");
                Integer pageSize = Integer.parseInt(hashMap.get("pageSize")+"");
                 /*start:就是当前页的起始索引,pageSize就是每页的条数
                pages:就是当前页
                */
                int start=(pages-1) * pageSize;
                Integer state = 0 ;
                List<UserWithdrawDeposit> list = userWithdrawDepositService.getUserWithdrawDeposit(start,pageSize,state,null);

                return new MassageJsons("0","修改成功",list,userWithdrawDepositDao.getUserWithdrawDepositCount(state,null));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new MassageJsons("1","修改失败");
    }

}
